package lookups.action;

import java.util.ArrayList;

import lookups.dao.TypeOfBusinessDAO;
import lookups.entity.TypeOfBusiness;

import com.opensymphony.xwork2.ActionSupport;

public class NextPageTOBAction extends ActionSupport {
	
	private String businessname;
	private String siccode;
	private int pageNum;
	private int PAGE_SIZE=6;
	private int totalPage;
	
	ArrayList<TypeOfBusiness> listtypeofbusiness;
	
	@Override
	public String execute() throws Exception {
		System.out.println("business name="+businessname);
		System.out.println("SICCode="+siccode);
		System.out.println("page num="+pageNum);
		if(pageNum<=0) pageNum=1;
		
		
		TypeOfBusinessDAO tobd=new TypeOfBusinessDAO();
		
		int totalresult=tobd.getTotalTypeOfBusiness(siccode, businessname);
		totalPage=totalresult/PAGE_SIZE;
		if(totalresult%PAGE_SIZE>0) totalPage++;
		System.out.println("total page="+totalPage);
		
		if(pageNum>=totalPage)pageNum=totalPage;
		else pageNum++;
		
		listtypeofbusiness=tobd.getListTypeOfBusiness(siccode, businessname,pageNum,PAGE_SIZE);
		if(listtypeofbusiness==null) return ERROR;
		return SUCCESS;
	}
	

	public int getPageNum() {
		return pageNum;
	}
	
	public void setPageNum(int pageNum) {
		this.pageNum = pageNum;
	}
	
	public int getTotalPage() {
		return totalPage;
	}

	public void setTotalPage(int totalPage) {
		this.totalPage = totalPage;
	}

	public String getBusinessname() {
		return businessname;
	}

	public void setBusinessname(String businessname) {
		this.businessname = businessname;
	}

	public String getSiccode() {
		return siccode;
	}

	public void setSiccode(String siccode) {
		this.siccode = siccode;
	}

	public ArrayList<TypeOfBusiness> getListtypeofbusiness() {
		return listtypeofbusiness;
	}

	public void setListtypeofbusiness(ArrayList<TypeOfBusiness> listtypeofbusiness) {
		this.listtypeofbusiness = listtypeofbusiness;
	}
	
}
